package com.bwf.lgqingdan.mvp.presenter.impl;

import com.bwf.lgqingdan.entity.ArticlesBean;
import com.bwf.lgqingdan.entity.ThingsBean;
import com.bwf.lgqingdan.mvp.model.SearchDataListModel;
import com.bwf.lgqingdan.mvp.model.impl.SearchDataListModelImpl;
import com.bwf.lgqingdan.mvp.presenter.SearchDataListPresenter;
import com.bwf.lgqingdan.mvp.view.SearchDataListView;
import com.bwf.lgqingdan.utils.Apis;
import com.bwf.lgqingdan.utils.UrlHandler;

import java.util.List;

/**
 * Created by Administrator on 2016/11/21.
 */

public class SearchDataListPresenterImpl implements SearchDataListPresenter, SearchDataListModel.Callback {
    private SearchDataListModel model;
    private SearchDataListView view;

    public SearchDataListPresenterImpl(SearchDataListView view) {
        this.view = view;
        this.model = new SearchDataListModelImpl();
    }

    @Override
    public void loadArticleData(String keyword) {
        String url = UrlHandler.handlUrl(Apis.API_SEARCH_ARTICLE,keyword);
        model.loadArticleData(url,this);
    }

    @Override
    public void loadThingData(String keyword) {
        String url = UrlHandler.handlUrl(Apis.API_SEARCH_THING,keyword);
        model.loadThingData(url,this);
    }

    @Override
    public void loadArticleSuccess(List<ArticlesBean> articles) {
        view.hideLoading();
        if(articles == null || articles.size() == 0){
            view.clearListDatas();
            view.showNoDataLayout();
        }else{
            view.showData(articles);
            view.hideNoDataLayout();
        }
    }

    @Override
    public void loadThingSuccess(List<ThingsBean> things) {
        view.hideLoading();
        if(things == null || things.size() == 0){
            view.clearListDatas();
            view.showNoDataLayout();
        }else{
            view.showData(things);
            view.hideNoDataLayout();
        }

    }

    @Override
    public void loadFailed(String failedMsg) {
        view.showLoadFailed(failedMsg);
    }
}
